package com.tr.rentcar.controller.houtai.base;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tr.rentcar.model.dao.FriendDao;
@WebServlet("/friendmodify")
public class FriendModifyControllor extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		resp.sendRedirect(req.getContextPath()+"/friendlink");
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		String pid=req.getParameter("pid");
		Integer pId=Integer.parseInt(pid);
		
		//1是修改
		if(pId==1){
			try {
			String id=req.getParameter("id");
			Integer Id=Integer.parseInt(id);
			String name=req.getParameter("name");
			String address=req.getParameter("address");
			
				new FriendDao().updatefriend(name, address, Id);
				
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		//11是添加
		if(pId==11){
			try {String name=req.getParameter("name");
				String address=req.getParameter("address");
				new FriendDao().save(name, address);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

		}
		doGet(req, resp);
	}
	
}
